package howl.types;



import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import compiler.HowlType;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Datum {
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	
	@Persistent
	private String name;
	
	@Persistent
	private Double Value;
	
	@Persistent
	private Unit unit;
	
	@Persistent
	private Long ParentID;
	
	@Persistent
	private Long GrandParentID;
	
	public Datum(TableDescriptor td,Entry e,String...args) {
		super();
		this.ParentID = e.getId();
		this.GrandParentID = td.getId();
		
		try {
			if ((args.length  == 2)) {
				this.name = args[0];
				this.Value = Double.parseDouble(args[1]);
				this.unit = td.lookupType(this.name);
			} else {

				
			}
		} catch (IllegalArgumentException e0){
			e0.printStackTrace();
		}catch (Exception e1) {
		
			e1.printStackTrace();
		}
	}	
	
	public Datum(TableDescriptor td,Entry e,String name, Double value) {
		super();
		this.name = name;
		this.Value = value;
		this.ParentID = e.getId();
		this.unit = td.lookupType(name);
		this.GrandParentID = td.getId();
	}	

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Double getValue() {
		return Value;
	}

	public void setValue(Double value) {
		this.Value = value;
	}

	public Unit getUnit() {
		return unit;
	}

	public void setUnit(Unit unit) {
		this.unit = unit;
	}

	public Long getParentID() {
		return ParentID;
	}

	public void setParentID(Long parentID) {
		ParentID = parentID;
	}

	@Override
	public String toString() {
		return "Datum [GrandParentID=" + GrandParentID + ", ParentID="
				+ ParentID + ", id=" + id + ", name=" + name + ", unit=" + unit
				+ ", value=" + Value + "]";
	}

	/**
	 * @return the grandParentID
	 */
	public Long getGrandParentID() {
		return GrandParentID;
	}

}

